package com.meilai.project.mapper.personal.handle;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.workflow.WFCheck;
import com.meilai.project.vo.personal.handle.CheckHistoryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 杨凯博
 * @date 2022/1/23 11:28
 */
@Mapper
public interface WFCheckHistoryMapper extends BaseMapper<WFCheck> {
    @Select("select a.node_id, a.node_name, a.`create_at`,a.`type`, b.`name` as user,IFNULL(a.`opinion`, \"\") as opinion from `wf_check` a left join `user` b on " +
            "a.`user_id`=b.`id`" +
            "WHERE a.`wf_data_id` =#{wf_data_id} and a.`data_id` =#{data_id} order by a.create_at desc")
    List<CheckHistoryVO> selectCheckHistoryList(@Param("wf_data_id") Long wf_data_id,@Param("data_id") Long data_id);

    @Select("SELECT " +
            "wd.`status` AS `wd_status` " +
            ", wc.id AS id " +
            ", wc.node_id " +
            ", wc.node_name " +
            ", wc.`create_at` " +
            ", wc.`type` " +
            ", u.`name` as `user`,IFNULL(wc.`opinion`, '') as opinion " +
            "FROM wf_check wc " +
            "JOIN `user` u ON wc.user_id=u.id " +
            "JOIN wf_data wd ON wc.wf_data_id=wd.id " +
            "JOIN work_flow_default wfd ON  " +
            "wd.work_flow_default_id=wfd.id " +
            "AND wfd.deleted_at IS NULL  " +
            "AND wfd.`status`=1  " +
            "AND wfd.flow_type=#{flow_type}  " +
            "WHERE wc.`data_id`=#{data_id}  " +
            "ORDER BY wc.create_at DESC")
    List<CheckHistoryVO> selectCheckHistoryList2(@Param("flow_type") Integer flow_type,@Param("data_id") Long data_id);
}
